package io.github.codelifeleno.jdbrelease.execute;

import cn.hutool.core.io.resource.ResourceUtil;
import io.github.codelifeleno.jdbrelease.config.JDBReleaseConfig;
import org.junit.jupiter.api.Test;

import java.io.File;

import static org.junit.jupiter.api.Assertions.*;

class JDBReleaseInitTest {

    @Test
    void initConfig() {
        JDBReleaseConfig init = new JDBReleaseInit().initConfig(ResourceUtil.getResourceObj("F:\\Datas\\Workspace\\GitOnlineProjects\\JDBRelease\\commons\\src\\test\\resources\\JDBReleaseConfig.xml"));
        assertNotNull(init);
        assertEquals("org.postgresql.Driver", init.getDb().getDriver());
        assertEquals("jdbc:postgresql://192.168.1.6:5432/demodb", init.getDb().getUrl());
        assertEquals("demouser", init.getDb().getUsername());
        assertEquals("demouser", init.getDb().getPassword());
        assertEquals("demouser", init.getDb().getSchema());
        assertEquals("PostgreSQL", init.getDb().getType());
        assertEquals("__", init.getFileConfig().getNameSplit());
        assertEquals("V", init.getFileConfig().getSimplePrefix());
        assertEquals("R", init.getFileConfig().getRollbackPrefix());
        assertEquals("A", init.getFileConfig().getAllwaysPrefix());
        assertEquals(".*${DB.Type}.sql", init.getFileConfig().getNameRegEx());
        assertEquals("/Develop/Datas/JDBRelease/Logs/", init.getLogsDirPath());
        assertArrayEquals(new String[]{"classpath:db/changelog"}, init.getFileDirPaths().toArray());
    }
}